<?php
 class Products extends CI_Model{
    
    function __construct(){
        parent::__construct();
    }
    
    /**
     * Get list product index
     * @author tien.nguyen
     * @return array
     */
    public function getListIndex(){
        $limit = $this->session->userdata('CONFIG_NUMBER_SHOW_PRODUCTS');        
        if(empty($limit)){
            $limit = 3;
        }
        
       $this->db->where('Visible', 1);
       $this->db->limit($limit);
       $this->db->order_by('CreatedDate', 'DESC');       
       $query = $this->db->get('products');
        
       return $query->result_array(); 
    }
    
    /**
     * Get list product for product list 
     * @author tien.nguyen
     */
    public function getListProduct($page = 1){
        $this->db->where('Visible', 1);
       $this->db->limit(10, ($page -1 ) * 10);
       $this->db->order_by('CreatedDate', 'DESC');
       $query = $this->db->get('products');
        
       return $query->result_array();
    }
    
    /**
     * Get list product for product list 
     * @author tien.nguyen
     */
    public function getListProductCate($cateId, $page = 1){
        $this->db->where('Visible', 1);
       $this->db->limit(10, ($page -1 ) * 10);
       $this->db->order_by('CreatedDate', 'DESC');
       $this->db->join('categories', 'categories.CategoryId = products.CategoryId');
       $this->db->where('categories.CategoryId = '.$cateId);
       $query = $this->db->get('products');
        
       return $query->result_array();
    }
    
    /**
     * Get product
     * @author tien.nguyen
     */
    public function getProduct($productId){
       $query = $this->db->get_where('products', array('ProductId' => $productId));
       return $query->row_array();
    }
 }
?>